<template>
  <views class="enterprise_statistic">
    <viewTitle :title="'企业统计'" :border="false"></viewTitle>

    <!-- 搜索栏  用户名 - 真实姓名 -->
    <div class="search flex flexC">
      <!-- 所属服务商-银行流水号-客户编号-记录类型 -->
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="search_input flex flexR center">
          <div class="customer_number flex flexR center">
            <el-form-item label="企业编码:">
              <el-input v-model="enterprise_serial" placeholder="请输入企业编码" :clearable="true"></el-input>
            </el-form-item>
          </div>

          <div class="their_facilitator flex flexR center">
            <el-form-item label="企业名称:">
              <el-input v-model="enterprise_name" placeholder="请输入企业名称" :clearable="true"></el-input>
            </el-form-item>
          </div>

          <div class="customer_number flex flexR center">
            <el-form-item label="代理商编码:">
              <el-input v-model="agent_sn" placeholder="请输入代理商编码" :clearable="true"></el-input>
            </el-form-item>
          </div>
        </div>

        <div class="search_input flex flexR center">
          <div class="their_facilitator flex flexR center">
            <el-form-item label="代理商名称:">
              <el-input v-model="agent_name" placeholder="请输入代理商名称" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <!-- 创建时间 -->
          <div class="creation_time flex flexR center">
            <el-form-item label="交易时间:">
              <el-date-picker
                v-model="pay_time"
                value-format="timestamp"
                type="datetimerange"
                align="right"
                :default-time="['0:00:00','23:59:59']"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions"
              ></el-date-picker>
            </el-form-item>
          </div>
        </div>

        <div class="search_input flex flexR center">
          <!-- 按钮（查询、重置、新增）   -->
          <el-form-item>
            <div class="flex flexR pay_btn_list">
              <el-button type="primary" @click="getData" icon="el-icon-search">查询</el-button>
              <el-button @click="reSet" icon="el-icon-refresh">重置</el-button>
              <el-button type="danger" icon="el-icon-download" @click="exportExcel">导出列表</el-button>
            </div>
          </el-form-item>
        </div>
      </el-form>
    </div>

    <!-- 展示列表 -->
    <div class="table_list">
      <el-table
        border
        :data="tableData"
        style="width: 80%;max-width:none;"
        :header-cell-style="getRowClass"
        :select-on-indeterminate="true"
        :fit="true"
        :lazy="true"
        @row-click="clickRow"
        max-height="450"
      >
        <el-table-column type="index" label="序号" width="50"></el-table-column>
        <el-table-column prop="enterprise_name" label="企业名称" ></el-table-column>
        <el-table-column prop="agent_sn" label="代理商编码" ></el-table-column>
        <el-table-column prop="agent_name" label="代理商名称" ></el-table-column>
        <el-table-column prop="qichu" label="期初余额" ></el-table-column>
        <el-table-column prop="real_money" label="充值总额" ></el-table-column>
        <el-table-column prop="process_commission" label="手续费" ></el-table-column>
        <el-table-column prop="charge1" label="充值(录入)" ></el-table-column>
        <el-table-column prop="charge2" label="充值(转账)" ></el-table-column>
        <el-table-column prop="issuing" label="代发金额" ></el-table-column>
        <el-table-column prop="qimo" label="期末余额" ></el-table-column>
        <el-table-column prop="zip" label="操作" width="150">
          <template slot-scope="scope">
            <div class="table_operation flex flexR">
              <el-button type="warning" @click="toDetail(scope)">明细</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--<div class="flex flexR paging">-->
      <!--<el-pagination-->
        <!--style="background:#fff; padding:10px 0"-->
        <!--background-->
        <!--layout="total, sizes,prev, pager, next, jumper"-->
        <!--@size-change="(page_size) => {this.pagination.page_size = page_size;this.getData()}"-->
        <!--@current-change="(page_size) => {this.pagination.page_start = page_size;this.getData()}"-->
        <!--:page-sizes="[10, 20, 30, 50]"-->
        <!--:page-size="pagination.page_size"-->
        <!--:total="pagination.total_count"-->
        <!--:current-page="pagination.current_page"-->
        <!--:page-count="pagination.page_count"-->
      <!--&gt;</el-pagination>-->
    <!--</div>-->
  </views>
</template>

<script>
export default {
  data() {
    return {
      pay_time: [], // 交易时间
      enterprise_name: "", // 企业名称
      enterprise_serial: "", // 企业编号
      agent_sn : "",
      agent_name : "",
      pagination: {
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      },
      download_url: "", // 导出
      tableData: [
        {
          user_name: "企业名称"
        }
      ],
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      }
    };
  },
  computed: {},
  methods: {
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    //     点击单行
    clickRow(row, column, event) {
      console.log(row, column, event);
    },
    //    修改是否换行
    changeStyleRow(width) {
      let _width = width - 290 - 350 - 300 - 50 - 25;
      if (_width > 300) {
        this.marginLeft = 25;
      } else {
        this.marginLeft = 0;
      }
    },
    getData() {
      if (this.pay_time && this.pay_time[0]) {
        this.pay_time_start = this.pay_time[0]/1000;
        this.pay_time_end = this.pay_time[1]/1000
      } else {
        this.pay_time_start = "";
        this.pay_time_end = "";
      }
      let data = this.$api.sendSync(this.$mapapi.f_enterpriseStatistics, {
        enterprise_sn: this.enterprise_serial, // 企业编号
        enterprise_name: this.enterprise_name, // 企业名称
        agent_sn:  this.agent_sn,
        agent_name :this.agent_name,
        pay_time_start: this.pay_time_start, // 开始时间
        pay_time_end: this.pay_time_end, // 结束时间
        pagination: this.pagination
      });
      if (data.code != 200 && data.code != 501) {
        this.$message.error(data.msg);
        return;
      }
      this.tableData = data.data.list || [];
      this.download_url = data.data.download_url;
      this.pagination = data;
      console.log("data", data);
    },
    reSet() {
      this.pay_time = []; // 交易时间
      this.enterprise_name = ""; // 企业名称
      this.enterprise_serial = ""; // 企业编号
      this.agent_sn = "";
      this.agent_name = "";
    },
    exportExcel() {
        this.$import_excal(this.download_url || "");
    },
    toDetail(data) {
      let { enterprise_id } = data.row || {};
      this.$toRoutePath({
        path: "/enterprise_statistic/enterprise_statistic_detail",
        edit: true,
        query: { enterprise_id: enterprise_id }
      });
    }
  },
  mounted() {
    this.getData();
  }
};
</script>


<style lang="less" scope="true"   src="@/style/statistics/enterprise_statistic.less">
</style>